package com.zhongfl.crm.event.handler;

import com.zhongfl.crm.event.LxChannelCreateEvent;
import com.zhongfl.crm.model.LxChannel;
import com.zhongfl.crm.service.ResolveService;
import org.springframework.stereotype.Service;
import tech.heptagram.channel.api.common.AssertUtils;
import tech.heptagram.channel.api.model.Channel;
import tech.heptagram.channel.api.service.ChannelService;

import javax.annotation.Resource;

/**
 * @author 木叶丸
 * @date 2019/3/5 14:53
 */
@Service
public class LxChannelCreateHandler implements LxChannelCreateEvent {

    @Resource
    private ChannelService channelService;

    @Resource
    private ResolveService resolveService;

    /**
     * 事件处理接口
     *
     * @param lxChannel 励销渠道信息
     */
    @Override
    public void handle(LxChannel lxChannel) {
        AssertUtils.notNull(lxChannel, "励销渠道信息不存在，渠道创建失败！");
        Channel channel = resolveService.resolve(lxChannel);
        channelService.save(channel);
    }
}
